package com.bite.forum.config;

import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@SecurityScheme(
        name = "BearerAuth",  // 原Springfox未配置鉴权，此处可选添加
        type = SecuritySchemeType.HTTP,
        scheme = "bearer",
        in = SecuritySchemeIn.HEADER
)
public class OpenAPIConfig {
    /**
     * 替代原 createApi() 方法功能
     * 定义接口分组及扫描范围
     */
    @Bean
    public GroupedOpenApi forumApiTest() {
        return GroupedOpenApi.builder()
                .group("test-api")  // 分组名称
                .packagesToScan("com.bite.forum.controller")  // 包扫描路径
                .pathsToMatch("/**")  // 路径匹配规则
                .build();
    }

    /**
     * 替代原 apiInfo() 方法功能
     * 配置文档元数据
     */
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("论坛系统API")
                        .version("1.0")
                        .description("论坛系统前后端分离API测试")
                        .contact(new Contact()
                                .name("DYH")
                                .url("https://blog.csdn.net/weixin_73792626?spm=1000.2115.3001.5343")
                                .email("2772067457@qq.com")));
    }
}